<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Home extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library('email');
        $this->load->model('email_model');
        $this->load->model('news/news_model');
        $this->load->model('category/category');
        for ($i = BIET_THU_LAU_DAI; $i <= THONG_TIN; $i++){
            $category_spot_list[$i] = $this->category->get_category_spots($i);
        }
        $this->data['category_spot_list'] = $category_spot_list;
    }

    public function index($cate = -1) {
        $this->data['menu_item'] = $cate;
        if ($cate == 0) {
            redirect('van-chuong');
        } else if ($cate == LIEN_HE) {
            $this->load->view('lien_he', $this->data);
        }else if ($cate == HO_TRO){
            $this->load->view('support', $this->data);
        } else {
            $this->load->view('home', $this->data);
        }
    }

    function contact() {
        $name = $this->input->post('name');
        $address = $this->input->post('address');
        $phone = $this->input->post('phone');
        $email = $this->input->post('email');
        $content = $this->input->post('content');


        //Config email
        $config_email = $this->email_model->get_email_info();
        $config['protocol'] = $config_email['protocol'];
        $config['smtp_host'] = $config_email['smtp_host'];
        $config['smtp_port'] = $config_email['smtp_port'];
        $config['smtp_timeout'] = $config_email['smtp_timeout'];
        $config['smtp_user'] = $config_email['smtp_user'];
        $config['smtp_pass'] = $config_email['smtp_pass'];
        $config['charset'] = $config_email['charset'];
        $config['newline'] = "\r\n";
        $config['mailtype'] = $config_email['mailtype'];

       
        $this->email->initialize($config);

        //Send Mail
        $this->email->from('lienhe@kientrucac.com.vn', 'Kiến trúc AC');

        $this->email->to($config_email['email_to']);

        $this->email->subject('Liên hệ');
        $email_msg = 'Họ và tên: ' . $name . '<br>';
        $email_msg .= 'Địa chỉ: ' . $address . '<br>';
        $email_msg .= 'Điện thoại: ' . $phone . '<br>';
        $email_msg .= 'Email: ' . $email . '<br>';
        $email_msg .= 'Nội dung: ' . $content . '<br>';

        $this->email->message($email_msg);
        $this->email->send();

        redirect('home');
    }
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */